PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

sh_file=$PWD/$0
sh_path=$(dirname $sh_file)
app_path=$(dirname $sh_path)
env_file=$sh_path/.env
function get_config()
{
  param=$1
  value=$(sed -E '/^#.*|^ *$/d' $env_file | awk -F "${param}=" "/${param}=/{print \$2}" | tail -n1)
  echo $value
}
tmp=$sh_path/tmp
app_name=$(get_config app_name)
remote=$(get_config remote)
remote_path=$(get_config remote_path)

if [ -a $tmp/$app_name.tar.gz ]; then
    echo 'scp 文件上传 start'
    scp $tmp/$app_name.tar.gz $remote:$remote_path
    echo 'scp 文件上传 end'

    echo 'ssh 命令 start'
    ssh -t $remote "cd $remote_path && tar -xzvf $app_name.tar.gz && rm -rf $app_name.tar.gz"
    rm -rf $tmp/$app_name*
    echo 'ssh 命令 end'
else
    echo '压缩包不存在，请先打包！'
fi